<template>
  <div id="app">
    <transition name="router-fade" mode="out-in">
      <keep-alive>
        <router-view/>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
// import {ToileInit} from './Toileto/ToileInit'
import {mapMutations, mapState,mapGetters} from 'vuex'
import YinsiSM from "./components/page/setmain/yinsiSM";

export default {
  name: 'App',
  data () {
    return {
      // ValueChangType: 1
    }
  },
  components: {
    YinsiSM

  },
  computed:{
    ...mapState([
        'ValueChangType','waitTimeXinDian','ConnectStatus','checkConnectRes'
    ])
  },
  watch: {
    // 如果路由有变化，会再次执行该方法
    "$route": "setToValueChangType",

    // ConnectStatus(val){
    //   if(val==false) {
    //
    //   }
    // }
  },
  methods: {
    ...mapMutations([ 'TOTLECALLBACK','SETValueChangeType','IniReciver','STARTYJ','STARTNJ','SETwaitTimeXinDian','SETXinDArray','initXinD','STOPXINDiNI',
      'AxiosPregnant','AxiosOvlation','AxiosSetuser','SETUSERID',"AxiosSeturine",'AxiosUrine','INIAPP','AxiosHearrate','checkConnectResMuT','isSaveXinLMUT',
      'yunPaiPageMUT'
    ]),
    stringToBytes ( str ) {
      var ch, st, re = [];
      for (var i = 0; i < str.length; i++ ) {
        ch = str.charCodeAt(i);  // get char
        st = [];                 // set up "stack"
        do {
          st.push( ch & 0xFF );  // push byte to stack
          ch = ch >> 8;          // shift value down by 1 byte
        }
        while ( ch )
        re = re.concat( st.reverse() );
      }
      return re
    },
    stopX () {
      this.STOPXINDiNI()
      window.setwaitTimeXinDian(1)
      clearInterval(window.setWaitTimeInter)
      this.IsReDoButton = true
      this.IsReCheckButton = true
      var reArray = this.stringToBytes('m00000-000-00\r\n')
      console.log('暂停' + reArray)
      window.writeFunction(reArray)
    },
    setToValueChangType () {
      this.IniReciver()
      if(this.$route.path == '/yunqi'){
        this.yunPaiPageMUT({val:'yunqi'})
      } else if(this.$route.path == '/pailuan'){
        this.yunPaiPageMUT({val:'pailuan'})
      }

      if(this.$route.path == '/yunqifirst'){
        this.yunPaiPageMUT({val:'yunqi'})
      } else if(this.$route.path == '/pailuanfirst'){
        this.yunPaiPageMUT({val:'pailuan'})
      }


      if (this.$route.path == '/index'){
        clearTimeout(window.setTitleSetTimeOut)
        window.setTitleSetTimeOut = setTimeout('window.hilink.setTitleVisible(true)',200)
      }
      if(this.$route.path == '/setmain'){
        window.hilink.setTitleVisible(false)
        this.SETValueChangeType({num: 0})
        var reArray = this.stringToBytes('m00000-000-00\r\n')
        window.writeFunction(reArray)
      }
      if ( this.$route.path == '/ctrlmain') {
        window.hilink.setTitleVisible(false)
        this.SETValueChangeType({num: 0})
        if (window.setIntervalId==false) {
          var reArray = this.stringToBytes('m00000-000-00\r\n')
          window.writeFunction(reArray)
          window.setIntervalId = setInterval("writeInterval()",1000)
        }
        // alert(this.ValueChangType)
      } else if(this.$route.path == '/yunqi'  || this.$route.path=='/pailuan'|| this.$route.path=='/niaojian') {
        this.AxiosPregnant()
        this.AxiosOvlation()
        this.AxiosUrine()
        window.hilink.setTitleVisible(false)
        if (window.setIntervalId==false) {
          var reArray = this.stringToBytes('m00000-000-00\r\n')
          window.writeFunction(reArray)
          window.setIntervalId = setInterval("writeInterval()",1000)
        }
        this.SETValueChangeType({num: 1})
        // alert(this.ValueChangType)
      } else if (this.$route.path == '/yunqifirst'  || this.$route.path=='/pailuanfirst'|| this.$route.path=='/niaojianfirst') {
        var u = navigator.userAgent
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        if (isiOS === true) {
          window.hilink.setTitleVisible(false)
          if (window.setIntervalId==false) {
            var reArray = this.stringToBytes('m00000-000-00\r\n')
            window.writeFunction(reArray)
            window.setIntervalId = setInterval("writeInterval()",1000)
          }
          this.SETValueChangeType({num: 1})
        }
      } else if (this.$route.path == '/xindian') {
        this.AxiosHearrate()
        window.hilink.setTitleVisible(false)
        clearInterval(window.setIntervalId)
        window.setIntervalId = false
        this.SETValueChangeType({num: 2})
      } else if (this.$route.path == '/xindianfirst') {
        window.hilink.setTitleVisible(false)
        clearInterval(window.setIntervalId)
        window.setIntervalId = false
        this.SETValueChangeType({num: 2})
        this.stopX()
      }  else if(this.$route.path == '/xindiansecond'){
        this.isSaveXinLMUT({val:false})
        this.initXinD()
      } else if(this.$route.path == '/xindianredo'){
        this.initXinD()
      }
      console.log(this.$route.path)

      if (this.$route.path.toLowerCase() == '/yunqithird') {
        this.checkConnectResMuT({val:false})
        clearTimeout(window.SetTimeOUTcjiance)
        window.SetTimeOUTcjiance = setTimeout("checkConnectResFunction()",400000)
        clearTimeout(window.yunqisetTimeOUTn);
        window.yunqisetTimeOUTn = setTimeout("startYjyc()", 180000)

        window.resetStartJianceTime()
        clearInterval(window.startJianceTimeInteval)
        window.startJianceTimeInteval = setInterval("window.speakTime(180)",1000)

      } else if(this.$route.path.toLowerCase() == '/pailuanthird') {
        this.checkConnectResMuT({val:false})
        clearTimeout(window.SetTimeOUTcjiance)
        window.SetTimeOUTcjiance = setTimeout("checkConnectResFunction()",400000)
        clearTimeout(window.pailuansetTimeOUTn);
        window.pailuansetTimeOUTn = setTimeout("startPjyc()", 180000)

        window.resetStartJianceTime()
        clearInterval(window.startJianceTimeInteval)
        window.startJianceTimeInteval = setInterval("window.speakTime(180)",1000)

      } else if(this.$route.path.toLowerCase() == '/niaojianthird') {
        this.checkConnectResMuT({val:false})
        clearTimeout(window.SetTimeOUTcjiance)
        window.SetTimeOUTcjiance = setTimeout("checkConnectResFunction()",400000)
        clearTimeout(window.niaojiansetTimeOUTn);
        window.niaojiansetTimeOUTn = setTimeout("startNjyc()", 30000)

        window.resetStartJianceTime()
        clearInterval(window.startJianceTimeInteval)
        window.startJianceTimeInteval = setInterval("window.speakTime(30)",1000)

      }

    },
    SetOpenId(){
      // window.hilink.setStorageSync('USERIDA','MDFAMTAwMjQwOTA5QGE5NTVlNTU3NTliaN2QyZDEyOTMzNjE4MGZhN2EzMmMwQDU2NzA0ZThhNmNiaYmJmMjgzMzAxNDZmZDI5MmRjZDFmNTUzYjc0YjNmMDdhNDU4NmQ0ODM4M2Zh')
      var self = this
      var u = navigator.userAgent
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
      if (hbs.isSupport()) {
        console.log('成功')
        hbs.config({
          appId: "100240909",
          jsApiList: ["signIn"]
        })
        hbs.ready(function () {
          var param = {
            "scope": "https://www.huawei.com/auth/account/base.profile",
            "needAuthCode": false
          }
          hbs.signIn(param, function (res) {
            window.hilink.setStorageSync('USERIDA',res.openId)
            self.SETUSERID({userid:res.openId,username:res.displayName})
            self.AxiosSetuser()
            // self.AxiosPregnant()
            // self.AxiosOvlation()
          }, function (error) {
            console.log(error)
            console.log(error.code + ":" + error.message)
          })
        })
        hbs.error(function (res) {
          console.log("回调失败")
          console.log(res)
        })
      }
    }
  },
  mounted () {
    window.IndexPage = false
    var isIndex = false
    if (isIndex === true) {
      this.SetOpenId()
      window.isFirstSETrELEN = false
      this.TOTLECALLBACK()
      var self = this
      window.checkConnectResFunction = function (){
        self.checkConnectResMuT({val:true})
      }
      window.eqTime = function(){
        var now = new Date()
        if (now.getTime() > self.exitTime){
          console.log('aagag')
          self.showLoading = false
          self.showAddtoAlert = true
          clearInterval(window.ADDTOOut)
        }
      }
      this.INIAPP();
      window.hilink.onBluetoothAdapterStateChange('onBluetoothAdapterStateChangeCallback');
      window.hilink.openBluetoothAdapter()

      window.hilink.onBLEConnectionStateChange ("connetState")
      var re = window.hilink.getCurrentRegisteredDevice('getCurrentRegisteredDeviceM')
    }

  },
  created (){


  }
}

</script>

<style>
  html,body{font-size:12px !important; background-color: white !important;}
  /*.aui-bar-nav{*/
    /*height:2.5rem  !important;*/
    /*background: #2a87ef ;*/
    /*z-index: 999999;*/
  /*}*/
  /**{*/
    /*margin: 0;*/
    /*padding: 0;*/
  /*}*/
  /*html{*/
    /*font-size:calc(100vw/750*100);*/
  /*}*/
  /*html,body{*/
    /*padding: 0 !important;*/
    /*margin: 0px;*/
  /*}*/
#app {
  /*overflow: hidden;*/
  /*font-family: 'Avenir', Helvetica, Arial, sans-serif;*/
  /*-webkit-font-smoothing: antialiased;*/
  /*-moz-osx-font-smoothing: grayscale;*/
  /*text-align: center;*/
  /*padding: 0px;*/
  /*margin:0px;*/
}
  .router-fade-enter-active{
    /*transition: opacity .5s;*/
    /*transition: all .15s ease;*/
  }
  .router-fade-enter {
    /*transform: translateX(-60rem);*/
    /*opacity: 0;*/
  }
  .router-fade-leave-active{
    /*transition: opacity .1s;*/
    /*transition: all .5s ease;*/
  }
  .router-fade-leave-active{
    /*transform: translateX(120rem);*/
    /*opacity: 0;*/
  }
</style>
